﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
<body>
    <h2>显示列表</h2>
    <table class="layui-table">
        <thead>
            <tr>
                <th>用户姓名</th>
                <th>用户手机号</th>
                <th>用户昵称</th>
            </tr>
        </thead>
        <tbody id="tb">
        </tbody>
    </table>
</body>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="~/scripts/layui-v2.5.6/layui/layui.js"></script>
<script>
    $(function(){
        Show();
    });
    function Show(){
        $.ajax({
            url: "/User/ShowUser",
            type: "get",
            dataType: "json",
            success: function(res) {
                console.log("返回的数据:", res);
                $("#tb").empty();
                if(res && res.length > 0){
                    var data = res.Data || res;
                    $.each(data, function(index, item){
                        console.log("当前项:", item);
                        var row = `
                            <tr>
                                <td>${item.userName }</td>
                                <td>${item.userPhone }</td>
                                <td>${item.userNickName}</td>
                            </tr>
                        `;
                        console.log("生成的行:", row);
                        $("#tb").append(row);
                    });
                } else {
                    $("#tb").append('<tr><td colspan="3" style="text-align:center">暂无数据</td></tr>');
                }
            },
            error: function(xhr, status, error) {
                console.log("Error:", error);
                console.log("Status:", status);
                console.log("Response:", xhr.responseText);
                $("#tb").append('<tr><td colspan="3" style="text-align:center">加载失败</td></tr>');
            }
        });
    }
</script>
